﻿//==================================================================
// Copyright (C) 2011 深圳市中旭企业管理股份有限公司
// 文件名: xzEmpInsurance.cs
// 作 者：代码自动生成
// 日 期：2013-03-29 14:13:46
// 描 述：
// 版 本：1.00
// 修改历史纪录
// 版 本  修改时间      修改人            修改内容
// 1.00             
//==================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;
using System.Text;
using Csla;
using lite;
using Csla.Validation;
using Csla.Data;
using System.Data.SqlClient;
using ZX.DAL;
using OpenExpressApp.ORM;

namespace ZX.EHR.Library
{
	/// <summary>
    /// 
    /// </summary>
	[Serializable]
    [Table(Name="xzEmpInsurance")]
    [ZX.DBModule.Table("xzEmpInsurance","ID")]
	public class xzEmpInsurance: ZX.DBModule.BaseEntity
	{
        
        #region Business Methods 业务方法
       
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< Guid > IDProperty = RegisterProperty(typeof(xzEmpInsurance),new PropertyInfo< Guid >("ID"));
        [DataObjectField(true, true)]
        [Column, PK]
        public Guid ID
        {
            get { return GetProperty(IDProperty); }
            set { SetProperty(IDProperty, value); }
        }
        
		/// <summary>
        /// 员工ID
        /// </summary>
        private static PropertyInfo< Guid > EmployeeIDProperty = RegisterProperty(typeof(xzEmpInsurance),new PropertyInfo< Guid >("EmployeeID"));
        [Column]
        public Guid EmployeeID
        {
            get { return GetProperty(EmployeeIDProperty); }
            set { SetProperty(EmployeeIDProperty, value); }
        }
		/// <summary>
        /// 年月
        /// </summary>
        private static PropertyInfo< string > YearMonthProperty = RegisterProperty(typeof(xzEmpInsurance),new PropertyInfo< string >("YearMonth"));
        [Column]
        public string YearMonth
        {
            get { return GetProperty(YearMonthProperty); }
            set { SetProperty(YearMonthProperty, value); }
        }
		/// <summary>
        /// 应收合计(社保局总共要扣除公司帐号的金额)
        /// </summary>
        private static PropertyInfo< decimal > AccountReceivableProperty = RegisterProperty(typeof(xzEmpInsurance),new PropertyInfo< decimal >("AccountReceivable"));
        [Column]
        public decimal AccountReceivable
        {
            get { return GetProperty(AccountReceivableProperty); }
            set { SetProperty(AccountReceivableProperty, value); }
        }
		/// <summary>
        /// 应收个人合计
        /// </summary>
        private static PropertyInfo< decimal > EmpAccountReceivableProperty = RegisterProperty(typeof(xzEmpInsurance),new PropertyInfo< decimal >("EmpAccountReceivable"));
        [Column]
        public decimal EmpAccountReceivable
        {
            get { return GetProperty(EmpAccountReceivableProperty); }
            set { SetProperty(EmpAccountReceivableProperty, value); }
        }
		/// <summary>
        /// 应收公司合计
        /// </summary>
        private static PropertyInfo< decimal > CoAccountReceivableProperty = RegisterProperty(typeof(xzEmpInsurance),new PropertyInfo< decimal >("CoAccountReceivable"));
        [Column]
        public decimal CoAccountReceivable
        {
            get { return GetProperty(CoAccountReceivableProperty); }
            set { SetProperty(CoAccountReceivableProperty, value); }
        }
		/// <summary>
        /// 工资(缴存基数)
        /// </summary>
        private static PropertyInfo< decimal > LaborageProperty = RegisterProperty(typeof(xzEmpInsurance),new PropertyInfo< decimal >("Laborage"));
        [Column]
        public decimal Laborage
        {
            get { return GetProperty(LaborageProperty); }
            set { SetProperty(LaborageProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< decimal > EndowmentLaborageProperty = RegisterProperty(typeof(xzEmpInsurance),new PropertyInfo< decimal >("EndowmentLaborage"));
        [Column]
        public decimal EndowmentLaborage
        {
            get { return GetProperty(EndowmentLaborageProperty); }
            set { SetProperty(EndowmentLaborageProperty, value); }
        }
		/// <summary>
        /// 养老保险个人交的金额
        /// </summary>
        private static PropertyInfo< decimal > EmpEndowmentProperty = RegisterProperty(typeof(xzEmpInsurance),new PropertyInfo< decimal >("EmpEndowment"));
        [Column]
        public decimal EmpEndowment
        {
            get { return GetProperty(EmpEndowmentProperty); }
            set { SetProperty(EmpEndowmentProperty, value); }
        }
		/// <summary>
        /// 养老保险公司交的金额
        /// </summary>
        private static PropertyInfo< decimal > CoEndowmentProperty = RegisterProperty(typeof(xzEmpInsurance),new PropertyInfo< decimal >("CoEndowment"));
        [Column]
        public decimal CoEndowment
        {
            get { return GetProperty(CoEndowmentProperty); }
            set { SetProperty(CoEndowmentProperty, value); }
        }
		/// <summary>
        /// 住房保险个人交的金额(公积金)
        /// </summary>
        private static PropertyInfo< decimal > EmpHousingProperty = RegisterProperty(typeof(xzEmpInsurance),new PropertyInfo< decimal >("EmpHousing"));
        [Column]
        public decimal EmpHousing
        {
            get { return GetProperty(EmpHousingProperty); }
            set { SetProperty(EmpHousingProperty, value); }
        }
		/// <summary>
        /// 住房保险公司交的金额(公积金)
        /// </summary>
        private static PropertyInfo< decimal > CoHousingProperty = RegisterProperty(typeof(xzEmpInsurance),new PropertyInfo< decimal >("CoHousing"));
        [Column]
        public decimal CoHousing
        {
            get { return GetProperty(CoHousingProperty); }
            set { SetProperty(CoHousingProperty, value); }
        }
		/// <summary>
        /// 工伤缴费工资
        /// </summary>
        private static PropertyInfo< decimal > CompoLaborageProperty = RegisterProperty(typeof(xzEmpInsurance),new PropertyInfo< decimal >("CompoLaborage"));
        [Column]
        public decimal CompoLaborage
        {
            get { return GetProperty(CompoLaborageProperty); }
            set { SetProperty(CompoLaborageProperty, value); }
        }
		/// <summary>
        /// 工伤保险个人交的金额
        /// </summary>
        private static PropertyInfo< decimal > EmpCompoProperty = RegisterProperty(typeof(xzEmpInsurance),new PropertyInfo< decimal >("EmpCompo"));
        [Column]
        public decimal EmpCompo
        {
            get { return GetProperty(EmpCompoProperty); }
            set { SetProperty(EmpCompoProperty, value); }
        }
		/// <summary>
        /// 工伤保险公司交的金额
        /// </summary>
        private static PropertyInfo< decimal > CoCompoProperty = RegisterProperty(typeof(xzEmpInsurance),new PropertyInfo< decimal >("CoCompo"));
        [Column]
        public decimal CoCompo
        {
            get { return GetProperty(CoCompoProperty); }
            set { SetProperty(CoCompoProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< decimal > UnemploymentLaborageProperty = RegisterProperty(typeof(xzEmpInsurance),new PropertyInfo< decimal >("UnemploymentLaborage"));
        [Column]
        public decimal UnemploymentLaborage
        {
            get { return GetProperty(UnemploymentLaborageProperty); }
            set { SetProperty(UnemploymentLaborageProperty, value); }
        }
		/// <summary>
        /// 失业保险个人交的金额
        /// </summary>
        private static PropertyInfo< decimal > EmpUnemploymentProperty = RegisterProperty(typeof(xzEmpInsurance),new PropertyInfo< decimal >("EmpUnemployment"));
        [Column]
        public decimal EmpUnemployment
        {
            get { return GetProperty(EmpUnemploymentProperty); }
            set { SetProperty(EmpUnemploymentProperty, value); }
        }
		/// <summary>
        /// 失业保险公司交的金额
        /// </summary>
        private static PropertyInfo< decimal > CoUnemploymentProperty = RegisterProperty(typeof(xzEmpInsurance),new PropertyInfo< decimal >("CoUnemployment"));
        [Column]
        public decimal CoUnemployment
        {
            get { return GetProperty(CoUnemploymentProperty); }
            set { SetProperty(CoUnemploymentProperty, value); }
        }
		/// <summary>
        /// 失业参保情况
        /// </summary>
        private static PropertyInfo< string > UnemploymentProperty = RegisterProperty(typeof(xzEmpInsurance),new PropertyInfo< string >("Unemployment"));
        [Column]
        public string Unemployment
        {
            get { return GetProperty(UnemploymentProperty); }
            set { SetProperty(UnemploymentProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< decimal > ProcreateLaborageProperty = RegisterProperty(typeof(xzEmpInsurance),new PropertyInfo< decimal >("ProcreateLaborage"));
        [Column]
        public decimal ProcreateLaborage
        {
            get { return GetProperty(ProcreateLaborageProperty); }
            set { SetProperty(ProcreateLaborageProperty, value); }
        }
		/// <summary>
        /// 生育保险个人交的金额
        /// </summary>
        private static PropertyInfo< decimal > EmpProcreateProperty = RegisterProperty(typeof(xzEmpInsurance),new PropertyInfo< decimal >("EmpProcreate"));
        [Column]
        public decimal EmpProcreate
        {
            get { return GetProperty(EmpProcreateProperty); }
            set { SetProperty(EmpProcreateProperty, value); }
        }
		/// <summary>
        /// 生育保险公司交的金额
        /// </summary>
        private static PropertyInfo< decimal > CoProcreateProperty = RegisterProperty(typeof(xzEmpInsurance),new PropertyInfo< decimal >("CoProcreate"));
        [Column]
        public decimal CoProcreate
        {
            get { return GetProperty(CoProcreateProperty); }
            set { SetProperty(CoProcreateProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< decimal > HospitalizationLaborageProperty = RegisterProperty(typeof(xzEmpInsurance),new PropertyInfo< decimal >("HospitalizationLaborage"));
        [Column]
        public decimal HospitalizationLaborage
        {
            get { return GetProperty(HospitalizationLaborageProperty); }
            set { SetProperty(HospitalizationLaborageProperty, value); }
        }
		/// <summary>
        /// 医疗保险个人交的金额
        /// </summary>
        private static PropertyInfo< decimal > EmpHospitalizationProperty = RegisterProperty(typeof(xzEmpInsurance),new PropertyInfo< decimal >("EmpHospitalization"));
        [Column]
        public decimal EmpHospitalization
        {
            get { return GetProperty(EmpHospitalizationProperty); }
            set { SetProperty(EmpHospitalizationProperty, value); }
        }
		/// <summary>
        /// 医疗保险公司交的金额
        /// </summary>
        private static PropertyInfo< decimal > CoHospitalizationProperty = RegisterProperty(typeof(xzEmpInsurance),new PropertyInfo< decimal >("CoHospitalization"));
        [Column]
        public decimal CoHospitalization
        {
            get { return GetProperty(CoHospitalizationProperty); }
            set { SetProperty(CoHospitalizationProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< decimal > AccidentalLaborageProperty = RegisterProperty(typeof(xzEmpInsurance),new PropertyInfo< decimal >("AccidentalLaborage"));
        [Column]
        public decimal AccidentalLaborage
        {
            get { return GetProperty(AccidentalLaborageProperty); }
            set { SetProperty(AccidentalLaborageProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< decimal > EmpAccidentalProperty = RegisterProperty(typeof(xzEmpInsurance),new PropertyInfo< decimal >("EmpAccidental"));
        [Column]
        public decimal EmpAccidental
        {
            get { return GetProperty(EmpAccidentalProperty); }
            set { SetProperty(EmpAccidentalProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< decimal > CoAccidentalProperty = RegisterProperty(typeof(xzEmpInsurance),new PropertyInfo< decimal >("CoAccidental"));
        [Column]
        public decimal CoAccidental
        {
            get { return GetProperty(CoAccidentalProperty); }
            set { SetProperty(CoAccidentalProperty, value); }
        }
		
        #endregion
        
        #region Validation Rules 验证规则
        //将验证规则与业务对象的属性联系在一起
        protected override void AddBusinessRules()
        {
            //AddRule的第一个参数是委托变量，也就是说是方法的变量
            ValidationRules.AddRule(CommonRules.StringRequired, "YearMonth");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("YearMonth", 100));
            ValidationRules.AddRule(CommonRules.StringRequired, "Unemployment");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Unemployment", 100));
            //base.AddBusinessRules();
        }
        #endregion
        
        #region Factory Methods 工厂方法

        public xzEmpInsurance(){}

        public static xzEmpInsurance New()
        {
            return DataPortal.Create< xzEmpInsurance>();
        }
        public static xzEmpInsurance Get(Guid ID)
        {
            return DataPortal.Fetch< xzEmpInsurance>(new SingleLazyCriteria< xzEmpInsurance, Guid>(ID, false));
        }
        public static void Delete(Guid ID)
        {
            DataPortal.Delete(ID);
        }

        //public override xzEmpInsurance Save()
        //{
            //return base.Save();
        //}
        #endregion
		
		#region Data Access 数据访问
        //由于DataPortal_create中没有对数据库的访问，所有标记了Runlocal特性，使得该方法只需在本地运行即可
        //如果代码中有访问数据库的方法，那么就不要用这个特性，使数据门户可以根据情况将此方法的运行选择在应用服务器还是本地
        [RunLocal()]
        protected override void DataPortal_Create()
        {
            //在此调用CheckRules对所有的属性进行验证规则的检查，这样检查只运行一次。
            ValidationRules.CheckRules();
        }


        //可以看到此方法没有标记任何特性
        //此方法要访问数据库所以不能标记本地，由于她没有任何数据库更新操作所以也无需事务性的保护
        //此方法调用结束后会隐含的调用MarkOld（）方法
        private void DataPortal_Fetch(Guid ID)
        {
            //通过连接字符串建立SQL连接对象，Using符号代表，范围释放的意思，SqlConnection对象会在此范围后被释放掉
             using (var ctx = ConnectionManager<SqlConnection>.GetManager(ConnectionStringNames))
            {
                IDb db = DbFactory.Instance.GetDb(ctx.Connection);
                IQuery q = db.Query();
                q.Constrain("ID").Equal(ID);
                var data = db.Select< xzEmpInsurance>(q)[0];
                LoadProperty(IDProperty, data.ID);
                LoadProperty(EmployeeIDProperty, data.EmployeeID);
                LoadProperty(YearMonthProperty, data.YearMonth);
                LoadProperty(AccountReceivableProperty, data.AccountReceivable);
                LoadProperty(EmpAccountReceivableProperty, data.EmpAccountReceivable);
                LoadProperty(CoAccountReceivableProperty, data.CoAccountReceivable);
                LoadProperty(LaborageProperty, data.Laborage);
                LoadProperty(EndowmentLaborageProperty, data.EndowmentLaborage);
                LoadProperty(EmpEndowmentProperty, data.EmpEndowment);
                LoadProperty(CoEndowmentProperty, data.CoEndowment);
                LoadProperty(EmpHousingProperty, data.EmpHousing);
                LoadProperty(CoHousingProperty, data.CoHousing);
                LoadProperty(CompoLaborageProperty, data.CompoLaborage);
                LoadProperty(EmpCompoProperty, data.EmpCompo);
                LoadProperty(CoCompoProperty, data.CoCompo);
                LoadProperty(UnemploymentLaborageProperty, data.UnemploymentLaborage);
                LoadProperty(EmpUnemploymentProperty, data.EmpUnemployment);
                LoadProperty(CoUnemploymentProperty, data.CoUnemployment);
                LoadProperty(UnemploymentProperty, data.Unemployment);
                LoadProperty(ProcreateLaborageProperty, data.ProcreateLaborage);
                LoadProperty(EmpProcreateProperty, data.EmpProcreate);
                LoadProperty(CoProcreateProperty, data.CoProcreate);
                LoadProperty(HospitalizationLaborageProperty, data.HospitalizationLaborage);
                LoadProperty(EmpHospitalizationProperty, data.EmpHospitalization);
                LoadProperty(CoHospitalizationProperty, data.CoHospitalization);
                LoadProperty(AccidentalLaborageProperty, data.AccidentalLaborage);
                LoadProperty(EmpAccidentalProperty, data.EmpAccidental);
                LoadProperty(CoAccidentalProperty, data.CoAccidental);
            }
        }

        [Transactional(TransactionalTypes.TransactionScope)]
        protected override void DataPortal_DeleteSelf()
        {
            //依然是调用下面的方法删除的，只是他此时可以获得自己的Id
            DataPortal_Delete(IDProperty);
        }
        #endregion

	}
}

